package com.studio77.guessLyric.sprite;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;

import com.studio77.guessLyric.core.GameSystem;
import com.wiyun.engine.nodes.Node;

public class KeyBoard extends Node {
	static final int columns = 10;
	static final int rows = 3;
	static List<KeyItem> items;

	public KeyBoard() {
		items = new ArrayList<KeyItem>();
		for (int i = 0; i < rows; i++) {
			for (int j = 0; j < columns; j++) {
				float x = GameSystem.KeyWidth * j + GameSystem.KeyWidth / 2.0f;
				float y = (GameSystem.KeyHeight * 3) - GameSystem.KeyHeight * i
						- GameSystem.KeyHeight / 2.0f;
				KeyItem item = new KeyItem();
				item.setPosition(x, y);
				this.addChild(item);
				items.add(item);
			}
		}
	}

	public void resetKeyboard(List<String> strs) {
		// 首先打乱
		if (strs.size() == 30) {
			// 交换
			Random r = new Random((new Date()).getTime());
			for (int i = 0; i < strs.size(); i++) {
				int x = r.nextInt(strs.size());
				String temp = strs.get(i);
				strs.set(i, strs.get(x));
				strs.set(x, temp);
			}
			for (int i = 0; i < strs.size(); i++) {
				items.get(i).setKey(strs.get(i));
				items.get(i).setVisible(true);
			}
		}
	}

}
